package com.framework.auth.service.impl;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
       /* if(StringUtils.isEmpty(username)) {
            throw new UsernameNotFoundException("UserDetailsService没有接收到用户账号");
        } else {
                List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
                return new User("root","admin",grantedAuthorities);
            }
        }

*/
//        if(StringUtils.isEmpty(username)) {
//        throw new UsernameNotFoundException("UserDetailsService没有接收到用户账号");
//    } else {
//        QQUserQuery query = new QQUserQuery();
//        query.setUsername(username);
//
//        /**
//         * 根据用户名，查询用户信息
//         */
//        ResponseResult result = userService.getQQUserAuth(query);
//        if (result == null) {
//            throw new InternalAuthenticationServiceException("UserDetailsService查询用户账号信息失败");
//        } else if (result.get("code").equals("300")) {
//            throw new UsernameNotFoundException(String.format("用户'%s'不存在", username));
//        } else {
//            QQUserAuth user = JSON.parseObject(JSON.toJSONString(result.get("QQUserAuth")), QQUserAuth.class);
//            List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
//            for (String role : user.getRoles()) {
//                grantedAuthorities.add(new SimpleGrantedAuthority(role));
//            }
//            /**
//             * 根据查询的用户信息，创建一个认证用户对象，用于用户认证
//             */
//            return new User(user.getUsername(), user.getPassword(), grantedAuthorities);
        return null;
    }

}

